<?php

class Admin_Model_Company extends Zend_Db_Table_Abstract
{
    protected $_name = 'company';
    public function getAllData(){        
        $query = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('c'=>$this->_name))
                        ->joinLeft(array('u'=>'user'),'c.userId = u.userId', array('u.email as userEmail'));
        return $this->fetchAll($query);        
    }
    public function getDataByCompanyId($comId){
        $query = $this->select()
                        ->setIntegrityCheck(false)
                        ->from($this->_name)
                        ->where('comId = ?',(int)$comId);
        return $this->fetchRow($query);
    }
    public function getDataByUserId($userId){
        $query = $this->select()
                        ->setIntegrityCheck(false)
                        ->from($this->_name)
                        ->where('userId = ?',(int)$userId);
        return $this->fetchRow($query);
    }        
    public function addData($data){        
        $data = array('userId'=> $data['userId'],
                'fullname'  => $data['fullname'],
                'shortName'  => $data['shortName'],
                'contact'   => $data['contact'],
                'phone'     => $data['phone']);                
        $idAdd = $this->insert($data);        
        return $idAdd;
    }
    public function updateData($comId = '',$data){        
        $data = array('userId'  => $data['userId'],
                'fullname'      => $data['fullname'],
                'shortName'     => $data['shortName'],
                'contact'       => $data['contact'],
                'phone'         => $data['phone'],
                'fax'           => $data['fax'],
                'mobile'        => $data['mobile'],
                'email'         => $data['email'],
                'address'       => $data['address'],
                'tax'           => $data['tax'],
                'website'       => $data['website'],
                'skype'         => $data['skype'],
                'yahoo'         => $data['yahoo'],
                'intro'         => $data['intro'],
                'logo'          => $data['logo']);                
        return $this->update($data, 'comId = '.(int)$comId);
    }            
    public function deleteData($id){        
        $this->delete('comId = '.(int)$id);
    }
}